<?php

namespace app\index\dao;

use app\common\model\LawCaseCategory;
use ShidianUtil\Thinkphp\Dao\DaoTrait;
use think\Collection;

/**
 * LawCaseCategoryDao 数据访问对象
 * Class LawCaseCategoryDao
 * @package app\dao
 * @method LawCaseCategory findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method LawCaseCategory insertActive(array $params, array $allow_field = [])
 * @method LawCaseCategory updateActive(LawCaseCategory $model, array $params, array $allow_field = [])
 * @method LawCaseCategory findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method LawCaseCategory updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(LawCaseCategory $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class LawCaseCategoryDao
{
    use DaoTrait;

    /**
     * @var \app\common\model\LawCaseCategory
     */
    private $baseModel;

    /**
     * LawCaseCategoryDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = LawCaseCategory::class;
    }

    /**
     * 首页 分类
     * @param $number
     * @return Collection
     */
    public function selectHome($number): Collection
    {
        return LawCaseCategory::order('ord', 'ASC')
            ->order('id', 'DESC')
            ->append(['smallPicImg'])
            ->limit($number)
            ->select();
    }

    /**
     * 案件类型 可选项
     * @return Collection
     */
    public function selectOptions(): Collection
    {
        return LawCaseCategory::order('ord', 'ASC')
            ->order('id', 'DESC')
            ->field(['id', 'name', 'smallPic'])
            ->append(['smallPicImg'])
            ->select();
    }
}
